import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { ItemData } from "../../resource/info/ItemData";
import { ItemConfig } from "../../resource/ItemConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { BaseItem } from "../common/BaseItem";
import { ShopOperType } from "./ShopOperType";
import { CareerUtil } from "../common/util/CareerUtil";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { Alert } from "../../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../common/alertwins/CheckBoxWin";
import { GainItemUtil } from "../common/util/GainItemUtil";
import { CursorManager } from "../../manager/CursorManager";
import { ItemInfo } from "../../resource/info/ItemInfo";
import { TItem } from "../../../../Message/Db/Tables/TItem";
type int = number;
//class ExchangeItemRender
    
    export  class ExchangeItemRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.createChildren();
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            this.doubleClickEnabled = true;
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOver);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this.shopItemInfo = arg1["shopItemInfo"] as ShopItemInfo;
            if (this.shopItemInfo && this.shopItemInfo.itemInfo) 
            {
                this._price = this.shopItemInfo.tshopSell.price;
                this._priceType = this.shopItemInfo.unit;
                this.itemInfo = this.shopItemInfo.itemInfo.item;
                this._itemData = new ItemData(this.itemInfo.code);
                this._priceItemInfo = ItemConfig.instance.getInfoByCode(this._priceType);
                if (this._priceItemInfo) 
                {
                    this._priceName = HTMLUtil.addColor(this._priceItemInfo.item.name, ColorConfig.instance.getItemColor(this._priceItemInfo.item.color).color);
                    this._unitText.htmlText = this._priceName;
                }
                this._itemData.additionalInfo = this.getExchangeInfo();
                if (ItemsUtil.isMount(this._itemData)) 
                {
                    this._propImage.toolTipType = ItemData.ToolTipType_Mounts;
                }
                else 
                {
                    this._propImage.toolTipType = ItemData.ToolTipType_Exchange;
                }
                this._propImage.itemData = this._itemData;
                this._propImage.drawNow();
                this._propImage.setSize(33, 33);
                this._nameLabel.htmlText = ItemsUtil.getItemName(this._itemData);
                this._nameLabel.drawNow();
                this._priceNumLabel.x = this._unitText.x + this._unitText.textWidth + 10;
                this._priceNumLabel.htmlText = "<font color=\'#B0EFFF\'>×" + this._price + "</font>";
                this.selected = true;
            }
            return;
        }

        /* internal  */createChildren(): void
        {
            this._windowCenterB = ResouceConst.getScaleBitmap("WindowCenterB");
            this._windowCenterB.width = 142;
            this._windowCenterB.height = 40;
            this.addChild(this._windowCenterB);
            this._itemBg = GlobalClass.getBitmap("PropBg");
            this._itemBg.width = 38;
            this._itemBg.height = 38;
            this._itemBg.x = 2;
            this._itemBg.y = 3;
            this.addChild(this._itemBg);
            this._nameLabel = new GLabel();
            this._nameLabel.x = 40;
            this._nameLabel.y = 2;
            this.addChild(this._nameLabel);
            this._priceNumLabel = new GLabel();
            this._priceNumLabel.x = 65;
            this._priceNumLabel.y = 20;
            this.addChild(this._priceNumLabel);
            this._unitText = new Object /* flash.text.TextField */();
            this._unitText.x = 40;
            this._unitText.y = 20;
            this.addChild(this._unitText);
            this._propImage = new BaseItem();
            this._propImage.label = "";
            this._propImage.move(5, 5);
            this.addChild(this._propImage);
            return;
        }

        public onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var event: Object /* flash.events.MouseEvent */;
            var itemCareer: int;
            var creerName: string;
            var content: string;
            var isNeedAlert: Boolean;
            var closeAlert: Function;

            var loc1;
            itemCareer = 0;
            creerName = null;
            content = null;
            isNeedAlert = false;
            event = arg1;
            if (ShopOperType.currentOperType == ShopOperType.BUY) 
            {
                itemCareer = this.shopItemInfo.itemInfo.item.career;
                creerName = "";
                if (itemCareer != 0) 
                {
                    creerName = CareerUtil.getEquipCareerName(itemCareer);
                    if (CareerUtil.isCareerSuit(itemCareer, Cache.instance.role.roleInfo.career)) 
                    {
                        creerName = HTMLUtil.addColor("，" + creerName, "#f0ea3f");
                    }
                    else 
                    {
                        creerName = HTMLUtil.addColor("，" + creerName, "#ff0000");
                        if (ItemsUtil.isFashionWeapon(this._itemData)) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(53100));
                            return;
                        }
                    }
                }
                if (this.shopItemInfo.tshopSell.canBuyBatch == 1) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ShopItemSelect, this.shopItemInfo, true));
                    return;
                }
                content = HTMLUtil.addColor(Language.getString(53063), "#f0ea3f") + HTMLUtil.addColor(this._price.toString(), "#ff0000") + HTMLUtil.addColor(Language.getString(53072), "#f0ea3f") + this._priceName + HTMLUtil.addColor(Language.getString(53064) + this._nameLabel.htmlText + creerName + Language.getString(53065), "#f0ea3f");
                isNeedAlert = !PulseSharedObject.isTodayNotTips("ExchangeAlert");
                if (isNeedAlert) 
                {
                    closeAlert = (arg1: int, arg2: Boolean): void
                    {
                        if (arg1 == Alert.OK) 
                        {
                            doExchange();
                            Alert.resetToDefault();
                        }
                        if (arg2) 
                        {
                            PulseSharedObject.save("ExchangeAlert", true);
                        }
                        return;
                    }
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.mode = Alert.Mode_NoneNotModal;
                    Alert.show(content, null, Alert.OK | Alert.CANCEL, null, closeAlert);
                }
                else 
                {
                    this.doExchange();
                }
            }
            return;
        }

        /* internal  */doExchange(): void
        {
            GainItemUtil.gainItemTip(this._itemData, this.doExchangeImpl, null);
            return;
        }

        /* internal  */doExchangeImpl(arg1: Object): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopBuyItem, {"itemInfo": this.shopItemInfo, "amount": 1, "priorityFlag": Cache.instance.shop.priorityFlag}));
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1 && this.itemInfo) 
            {
                this.filters = [new Object /* flash.filters.GlowFilter */(3856353, 1, 6, 6, 1, 1, false, false)];
            }
            else 
            {
                this.filters = [];
            }
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (ShopOperType.currentOperType == ShopOperType.BUY) 
            {
                CursorManager.showCursor(CursorManager.BUY);
            }
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.hideCursor();
            return;
        }

        /* internal  */getExchangeInfo(): string
        {
            return HTMLUtil.addColor(Language.getString(53073), "#f0ea3f") + HTMLUtil.addColor(this._price.toString(), "#ff0000") + HTMLUtil.addColor(Language.getString(53072), "#f0ea3f") + this._priceName;
        }

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_propImage: BaseItem;

        /* internal */ /* var */_priceNumLabel: GLabel;

        /* internal */ /* var */_unitText: Object /* flash.text.TextField */;

        /* internal */ /* var */_windowCenterB: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_price: int;

        /* internal */ /* var */_priceType: int;

        /* internal */ /* var */_priceName: string;

        /* internal */ /* var */_priceItemInfo: ItemInfo;

        /* internal */ /* var */shopItemInfo: ShopItemInfo;

        /* internal */ /* var */itemInfo: TItem;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */toAdd: Boolean=true;
    }
